package com.ty.user.starter.entity.criteria;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDate;

/**
 * mybatis分页统一工具类
 *
 * @author lxm
 * @version 1.0
 * @date 2020/8/27
 */
@Data
@NoArgsConstructor
public class PageCriteria implements Serializable {

    private static final long serialVersionUID = -3662764539033751163L;
    @ApiModelProperty(name = "current", value = "当前页")
    private Long current = 1L;

    @ApiModelProperty(name = "size", value = "显示条数")
    private Long size = 10L;

    @ApiModelProperty(name = "search", value = "搜索内容")
    @Length(max = 50, message = "搜索内容不能超过50个字")
    private String search;

    @ApiModelProperty(name = "startDate", value = "开始日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate startDate;

    @ApiModelProperty(name = "endDate", value = "结束日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate endDate;

    public Page<?> defaultPage() {
        return new Page<>(current, size);
    }
}
